<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE xsl:stylesheet SYSTEM "lang://photos">

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">	
	
	<xsl:include href="../main.xsl" />
	<xsl:include href="menu.xsl" />
	<xsl:include href="albumBar.xsl" />

	<xsl:template match="/data">
		<html>
		
		<head>
			<title>
				<xsl:value-of select="$pageTitle" />
			</title>
			<xsl:call-template name="meta-head" />
			<link rel="stylesheet" href="{$baseURI}/css/photos.css" type="text/css" media="all" />
			<script type="text/javascript" src="{$baseURI}/js/photos.js" />
		</head>
		<body>
			
			<xsl:call-template name="top-userbar" />

			<div id="header">
				<xsl:call-template name="logo" />

				<xsl:call-template name="menu" />
			</div>

			<div id="blocks">
				<div id="blocks_inner">
					<xsl:call-template name="default-blocks-top" />
				</div>
			</div>

			<div id="content">
				<div id="content_inner">
					<xsl:apply-templates select="response" />
				</div>
			</div>

			<xsl:call-template name="footer" />
		</body>
		</html>
	</xsl:template>
	
	<xsl:template match="response[@album-id = '0']">
		<h1>&labelAskUploadAlbum;</h1>
		
		<xsl:apply-templates select="error" />
		
		<p>
			<select onchange="if(this.value!=0)document.location.href='{$baseURI}/photos/upload/'+this.value">
				<option value="">-- &labelChooseAlbum; --</option>
				
				<xsl:apply-templates select="document('xmodule://photos/getUserAlbumsSelection')/data/response/object" mode="album-option">
					<xsl:sort select="property[@name='title']/value" />
				</xsl:apply-templates>
				
			</select>
		</p>
		
		<p>&labelCanCreateAlbum1; <a href="{$baseURI}/photos/create_album">&labelCanCreateAlbum2;</a>?</p>
	</xsl:template>
	
	<xsl:template match="response[@album-id != '0']">
		<xsl:param name="albumId" select="@album-id" />
		
		<xsl:apply-templates select="document(concat('xobject://photoalbum/', $albumId))/data/object" mode="album-bar" />
		
		<h1>&labelPhotosUpload;</h1>
		
		<xsl:apply-templates select="error" />
		
		<form action="{$baseURI}/photos/upload/{$albumId}/go" method="post" enctype="multipart/form-data">
			<xsl:call-template name="file_field">
				<xsl:with-param name="max" select="@max-upload" />
				<xsl:with-param name="released" select="number (1)" />
			</xsl:call-template>
			
			<p>
				<input type="submit" value="&labelToUpload;" />
			</p>
		</form>
	</xsl:template>
	
	<xsl:template name="file_field">
		<xsl:param name="max" />
		<xsl:param name="released" />
		
		<br /><input type="file" name="photo[{$released}]" />
		
		<xsl:if test="$released &lt; $max">
			<xsl:call-template name="file_field">
				<xsl:with-param name="max" select="$max" />
				<xsl:with-param name="released" select="$released + 1" />
			</xsl:call-template>
		</xsl:if>
	</xsl:template>
	
	<!-- ALBUM OPTION -->
	<xsl:template match="object[@type='photoalbum']" mode="album-option">
		<option>
			<xsl:if test="@selected = '1'">
				<xsl:attribute name="selected"><xsl:text>selected</xsl:text></xsl:attribute>
			</xsl:if>
			<xsl:attribute name="value">
				<xsl:value-of select="@id" />
			</xsl:attribute>
			<xsl:value-of select="property[@name='title']/value" />
		</option>
	</xsl:template>
	
</xsl:stylesheet>